package com.starlink.common.log.interceptor;

import com.starlink.common.log.UserInfoFunction;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: lichao
 * @date: 2021-06-19 11:00:54
 */
public class UserInfoHandlerInterceptor implements HandlerInterceptor {
    private final UserInfoFunction userInfoFunction;

    public UserInfoHandlerInterceptor(UserInfoFunction userInfoFunction) {
        this.userInfoFunction = userInfoFunction;
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        userInfoFunction.save(request);
        return true;
    }
}
